// main class
function Sprite() {

	this._parent = null;
	this._x = 0;
	this._y = 0;
	this._width = 0;
	this._height = 0;

	this._childs = new Array();
}


// properties
Sprite.prototype.setX = function(value) {
	this._x = value;
};

Sprite.prototype.getX = function() {
	return this._x;
};

Sprite.prototype.setY = function(value) {
	this._y = value;
};

Sprite.prototype.getY = function() {
	return this._y;
};

Sprite.prototype.setWidth = function(value) {
	this._width = value;
};

Sprite.prototype.getWidth = function() {
	return this._width;
};

Sprite.prototype.setHeight = function(value) {
	this._height = value;
}

Sprite.prototype.getHeight = function() {
	return this._height;
}

// methods

Sprite.prototype.addChild = function(child) {
	this._childs.push(child);
	child._parent = this;
}

Sprite.prototype.removeChild = function(child) {
	for(i = 0; i<this._childs.length; i++)
		if(this._childs[i] === child) {
			this._childs.splice(i,1);
			child._parent = null;
			return child;
		}
}

Sprite.prototype.getChildIndex = function(child) {
	for(i = 0; i<this._childs.length; i++)
		if(this._childs[i] === child)
			return i;
}

Sprite.prototype.setChildIndex = function(child, index) {
	this.removeChild(child);
	this._childs.splice(index,0,child);
}

Sprite.prototype.layout = function(context) {
	for(i = 0; i<this._childs.length; i++)
		if(this._childs[i].layout)
			this._childs[i].layout(context);
}

Sprite.prototype.render = function(context) {
	for(i = 0; i<this._childs.length; i++)
		if(this._childs[i].render)
			this._childs[i].render(context);
}
